<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        width: 110px;
        color: black;
        background-color: aqua;
    }
</style>
<body>
    <button> 显示当前的时间</button>
    <div>时间</div>
    <script>
        //1,获取元素
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        //2，注册事件
        btn.onclick = function(){
            //3，添加处理程序
            div.innerText = getDate();
        }
        function getDate(){
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth();
            var dates = date.getDate();
            return year + '-' + month + '-' + dates + ' ';
        }
    </script>
</body>
</html>